package thread;

/**
 * 通过实现Runnable接口来创建线程
 */
class MyRunnable implements Runnable {
    public void run() {
        //描述了线程要完成的逻辑
        while(true) {
            System.out.println("hello thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class Demo2 {
    public static void main(String[] args) {
        MyRunnable runnable=new  MyRunnable();
        Thread thread=new Thread(runnable);
        thread.start();

        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
